<?php
namespace app\common\customer\model;

use think\Model;
use think\model\concern\SoftDelete;
use app\common\config\logic\DictionaryLogic;
use app\common\config\model\ConfigStore;
use app\common\product\logic\StoreCategoryLogic;

class CustomerMami extends Model
{
    protected $table = "tk_member_mami";
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $hidden = ['delete_time'];
    protected $type = [
        'entry_time' => 'timestamp',
    ];

    public function getStoreAttr($value, $data)
    {
        $dictionaryLogic = new DictionaryLogic();
        $store = $dictionaryLogic->getItem($data['store_id'], ConfigStore::class, ['id', 'title']);

        if (empty($store)) {
            $store = [
                'id' => '',
                'title' => ''
            ];
        }

        return $store;
    }

    public function getCategoryAttr($value, $data)
    {
        $categoryLogic = new StoreCategoryLogic();
        return $categoryLogic->getStoreCategory($data['category_id'], ['id', 'title', 'customer_model', 'order_model', 'on_member_company', 'is_sale']);
    }
}